package controllers;

import java.io.IOException;

import boundarys.ManageTypesGUI;
import ccrm.ClientMain;
import entitys.Category;
import entitys.Request;
import entitys.Session;
import entitys.Type;
import enums.Command;

public class ManageTypesController {
	ManageTypesGUI mtc;

	public ManageTypesController(ManageTypesGUI mtc)
	{
		this.mtc=mtc;
	}
	
	/**
	 * sends request to server to get the product types list
	 */
	public static void getProductTypes()
	{
		Request r =new Request(Command.GET_PRODUCT_TYPES,Session.getEmployee().getUserId());
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 
	}
	
	/**
	 * sends request to server to get the product types list that contains a string 
	 * @param text
	 */
	public static void getProductTypes(String text) {
		// TODO Auto-generated method stub
		Request r =new Request(Command.GET_PRODUCT_TYPES_WITH_PREFIX,Session.getEmployee().getUserId(), new Type(text));
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * sends requests to server to add new type to the database
	 * @param type
	 * @param listamount
	 */
	public static void addType(String type, int listamount)
	{
		Request r =new Request(Command.ADD_TYPE,Session.getEmployee().getUserId(), new Type(type, listamount+1));
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * sends request to server to change the name of the type name
	 * @param newtype
	 * @param index
	 */
	public static void editType(String newtype, int index) {
		// TODO Auto-generated method stub
		Request r =new Request(Command.EDIT_TYPE,Session.getEmployee().getUserId(), new Type(newtype, index));
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * sends request to server to delete the type
	 * @param type
	 * @param index
	 */
	public static void deleteType(String type, int index) {
		// TODO Auto-generated method stub
		Request r =new Request(Command.DELETE_TYPE,Session.getEmployee().getUserId(), new Type(type, index));
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

